<template>
  <div class="article-container">
    <!-- 导航栏 -->
    <van-nav-bar fixed title="文章详情">
      <van-icon @click="$router.back()" slot="left" name="arrow-left" />
    </van-nav-bar>
    <div class="detail-wrap">
      <!-- 标题 -->
      <h1 class="articleTitle">{{ article.title }}</h1>

      <!-- 作者信息 -->
      <div class="aut-box">
        <van-image round fit="cover" :src="article.aut_photo" />
        <div class="info">
          <div>渠梦臣</div>
          <span style="color: gray">计算机应用技术2班</span>
        </div>
        <van-button icon="plus" round type="info">关注</van-button>
      </div>

      <!-- 文章内容 -->
      <div class="articleContents markdown-body" v-html="article.content"></div>
      <p class="end">
        ______________________
        <br />
        end
      </p>
    </div>
    <!-- 文章评论列表区域 -->
    <articleComment :source="article.art_id" :target="article.art_id" />
  </div>
</template>

<script>
import articleComment from "./components/articleComment.vue";
import { getArticleDetailAPI } from "@/api";
export default {
  components: {
    articleComment,
  },
  props: {
    articleId: {
      type: [Number, String, Object],
      required: true,
    },
  },
  data() {
    return {
      article: {}, //文章详情
    };
  },
  created() {
    this.loadArticle();
  },
  methods: {
    async loadArticle() {
      try {
        const { data } = await getArticleDetailAPI(this.articleId);
        this.article = data.data;
      } catch (err) {
        console.log(err);
      }
    },
  },
};
</script>

<style lang="less" scoped>
@import "./styles/github-markdown.css";
.article-container {
  .detail-wrap {
    padding: 80px 10px;
    .articleTitle {
      font-size: 48px;
    }
    .aut-box {
      display: flex;
      margin: 20px auto;
      align-items: center;
      .van-button {
        height: 72px;
      }
      .van-image {
        width: 120px;
        height: 120px;
        margin-right: 20px;
      }

      .info {
        font-size: 22px;
        // 设置它在主轴方向上剩余空间的占比
        flex: 1;
      }
    }
    .end {
      color: #8393d0;
      margin: 0 auto;
      text-align: center;
      font-size: 48px;
    }
  }
}
</style>
